<title>数据查询</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb" lay-separator=">">
        <a lay-href=""><i class="layui-icon layui-icon-locate"></i>您当前的位置：</a>
        <a><cite class="first-breadcrumb">减灾司</cite></a>
        <a><cite class="second-breadcrumb">数据查询</cite></a>
    </div>
</div>

<div class="layui-fluid custom-dataSearch-page">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md2 layui-col-lg2 left-side">
            <div class="layui-card">
                <div class="layui-card-header">
                    <img src="../../../../dist/style/res/formFill/tem-task.png" class="card-header-icon"/>
                    <span class="card-header-title">查询区</span>
                </div>
                <div class="layui-card-body task-body">
                    <div style="padding: 0 10px">
                        <button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-urge layui-btn-disabled T-btn" data-target="urge">
                            <i class="layui-icon layui-icon-release"></i>催办
                        </button>
                    </div>
                    <!-- <ul id="queryListBox" class="queryListBox"></ul> -->
                    <ul id="treeDemo" class="ztree"></ul>
                </div>
            </div>
        </div>
        <div class="layui-col-md10 layui-col-lg10 right-side">
            <div class="queryFormBox">
                <div style="margin-top: 9px;margin-left: 10px;display: inline-block;">
                    <!-- <button type="button" class="layui-btn layui-btn-sm layui-btn-save T-event" data-target="save">保存</button>  -->
                    <button type="button" class="btn-color layui-btn layui-btn-sm layui-btn-save T-event"   data-target="save"> 保存 </button> 
                    <span class="depNameBox"></span>
                </div> 
                <form id="disFormBox"> 
                    <div id="layui-query-box" class="layui-form" lay-filter="query-condition-filter"></div>
                </form>
            </div>
           
            <div class="layui-card form-box">
                <div class="layui-card-header" style="padding: 0 9px 6px 9px;">
                    <div>
                        <button class="layui-btn T-btn btn-subform" data-target="submit">导出数据</button> 
                        单位名称： <div  class="layui-inline"> 
                            <input type="text" name="dept_name" class="layui-input" id="dept_name"/>
                        </div> 
                        <button class="layui-btn query-btn" id="query">查询</button>
                    </div>
                    <div class="layui-inline kq-time" style="display: none;">填报时间：<span class="kq-starttime"></span>~<span class="kq-endtime"></span></div>
                </div>
                <div class="layui-card-body" style="padding: 0;">
                    <div class="layui-tab layui-form layui-tab-card otherForm-content" lay-filter='tabSwitch'>  
                        <div class="layui-tab-content form-tab-content"> 
                                <table id="test-table-cellEdit" lay-filter="test-table-cellEdit"></table> 
                        </div>
                    </div>
                    <div id="data-dataSearch-kqform" class="kqform kqform-content"></div>
                </div>
            </div>
        </div>
    </div>
</div>

     

    <!-- 查询条件模板 -->
    <script type="text/html" id="queryExihibt">
            <div class="query-box">
                <div class="layui-row query-condition">
                    <div class="layui-col-md12 left-card-body">
                        {{# if(d && d.length > 0){ }}
                            {{# layui.each(d, function(index, item){ }}
                                <div class="layui-inline">
                                    <label class="layui-form-label" lay-tips="{{item.column_comment}}">{{item.column_comment}}：</label>
                                    {{# if(item.isSelect){ }}
                                        <div class="layui-input-inline">
                                            <select lay-ignore name={{item.column_name}} datatype={{item.datatype}}>
                                                <option value="">请选择数据</option>
                                                {{# layui.each(item.selectData, function(i, content){ }}
                                                    <option value="{{content.text}}">{{content.text}}</option>
                                                {{# }) }}
                                            </select>
                                        </div>
                                    {{# }else if(item.datatype == 'date'){ }}
                                        <div class="layui-input-inline" style="width: 120px;">
                                            <input type="text" name={{item.column_name}} datatype={{item.datatype}} placeholder="开始时间" autocomplete="off" class="layui-input condition-starttime">
                                        </div>
                                        <div class="layui-input-inline" style="width:5px;">-</div>
                                        <div class="layui-input-inline" style="width: 120px;">
                                            <input type="text" name={{item.column_name}} datatype={{item.datatype}} placeholder="结束时间" autocomplete="off" class="layui-input condition-endtime">
                                        </div>
                                    {{# }else{ }}  
                                        <div class="layui-input-inline">
                                            <input  type={{item.data_type=='int'||item.data_type=='decimal'?'number':'text'}} inputType={{item.data_type}} name={{item.column_name}} datatype={{item.datatype}} autocomplete="off" class="layui-input valifyInput">
                                        </div>
                                    {{# } }}
                                </div>
                            {{# }) }}
                        {{# }else{ }}
                            <div class="no-data-tips" style="margin-top:10px;"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">无查询条件</p></div>
                        {{# } }}
                    </div>
                </div>
            </div>
    </script>

     <!-- 单位单选框 -->
    <script type="text/html" id="unitRadios">
        {{#  if(d && d.length > 0){ }}
            {{# layui.each(d, function(index, item){ }}
                <input type="radio" name="dept" value="{{item.dept_id}}" title="{{item.dept_name}}" lay-filter="custom-unit-radio" {{item.checked ? "checked" : ""}} />
            {{# }) }}
        {{#  } }}
    </script>

<style>
    .layui-card-header{ 
    }
    .queryFormBox .layui-btn-save{ 
        background: url(../../dist/style/res/formFill/saveForm.png) no-repeat 6px center;
        padding: 0px 10px 0px 30px;
    }
    .queryFormBox .btn-color{
        background-color: #2669B1;
    }
    .queryFormBox{
        background: #FAFCFF;
        border-radius: 5px;
        border: 1px solid #D5E4F5;
        margin-bottom: 13px;
        box-shadow: 0 1px 2px 0 rgba(0,0,0,.05);
    }
     .my-table-btn-edit{
        color: #FD9404 !important;
        border-color: #FD9404;
    }
    .layui-icon-edit:before{
        content: "\e642";
    }
     .my-table-btn{
        font-size: 20px;
        border-width: 1px;
        border-style: solid;
        border-radius: 4px;
        margin-right: 4px;
        vertical-align: top;
    }
    .left-side .layui-card{
        height: 842px;
        border-radius: 4px;
        padding: 0 13px 0 20px;
        background: #F2F7FD;
        overflow: hidden;
    }
    .layui-card-header{
        height: 60px; 
        border-bottom: 1px solid #D2D2D2;
        padding: 0 0 6px 0;
        line-height: 60px;
    }
    .card-header-icon{
        width: 18px;
        height: 18px;
    }
    .card-header-title{
        line-height: 30px;
        margin-left: 8px;
    }
    .task-body{
        height: 765px;
        background: #FAFCFF;
        border: 1px solid #A3C4ED;
        border-radius: 5px;
        margin-top: 10px;
        padding: 5px 0;
    }
    .layui-btn-urge{
        margin-left: 13px;
        background-color: #2669B1;
    }
    .ztree{
        height: 97%;
        overflow: scroll;
    }
    .ztree *{
        padding: 0;
        font-size: 15px;
        font: inherit;
    }
    .query-box{
        min-height: 146px;
        overflow: auto;
    }
    .form-box{
        min-height: 555px;
        background: #F2F7FD;
        border-radius: 4px;
        border: 1px solid #90ABCD;
        overflow: auto;
    }
    .select-form-header{
        position: relative;
    }
    .card-header-right{
        position: absolute;
        right: 0;
        top: 0;
    }
    .layui-card .layui-tab{ 
        z-index: 9999;
    }
    .layui-tab-card>.layui-tab-title{
        background: #fff;
    }
    .layui-tab-card{
        border-top: none;
    }
    .select-form-box{
        padding: 10px 10px 0 15px;
        min-height: 400px;
    }
    .btn-subform, .query-btn{
        height: 30px;
        line-height: 30px;
        font-weight:600;
        padding-left: 31px;
        color: #FFFFFF;
        cursor: pointer;
    }
    .btn-subform{
        width: 96px;
        background: url('/dist/style/res/formFill/form-submit.png') no-repeat #2669B1;
        background-position: 7px 5px;
        margin-right: 10px;
    }
    .query-btn{
        width: 71px;
        background: url('/dist/style/res/formFill/search.png') no-repeat 10px center;
        background-color: #77AF6F;
        margin-right: 10px;
    }
    .layui-tab-content{
        padding: 15px 9px;
    }
    .layui-table tbody tr.bgRed{
        background: red;
    }
    #test-table-cellEdit1{
        width: 100%;
        text-align: center;
    }
    .addLine, .delLine, .checkLine{
        position: relative;
        width: 24px;
        height: 22px;
        border: none;
        background-position: center center;
        background-repeat: no-repeat;
        margin-top: 4px;
        cursor: pointer;
    }
    .addLine{
        background: url(../../../../dist/style/res/formFill/add.png);
        margin-right: 40px;
    }
    .delLine{
        background: url(../../../../dist/style/res/formFill/del.png);
    }
    .checkLine{
        background-color: transparent;
        border: 1px solid #FF4E32;
        border-radius: 2px;
    }
    .checkLine .layui-icon{
        position: absolute;
        top: -1px;
        left: 2px;
        font-size: 19px;
        color: #FF4E32 !important;
		border-color: #FF4E32;
    }
    .layui-table[lay-even] tbody tr:nth-child(odd) {
        background: #D3E5FF;
    }
    .layui-table[lay-even] tbody tr:nth-child(even) {
        background: #fff;
    }
    .layui-table thead tr {
        background-color: #2669B1 !important;
        color: #fff;
    }
    .layui-table td, .layui-table th{
        text-align: center;
    }

    .left-card-body{
        box-sizing: border-box;
        height: 100%;
        padding: 10px 0 0 0;
        overflow-y: scroll;
    }
    .left-card-body .layui-form-label{
        width: 160px;
        padding: 9px 10px;
        line-height: inherit;
        color: #373737;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .left-card-body .layui-inline{
        width: 33%;
        margin-bottom: 15px;
    }
    .left-card-body .layui-input, .left-card-body select{
        width: 100%;
        padding-left: 10px;
        height: 37px;
        line-height: 37px;
        border: 1px solid #E4E4E4;
        border-radius: 6px;
        background-color: #F0F5F7;
    }
    .left-card-body .layui-input-inline{
        width: 200px;
    }
    .right-card-body{
        position: relative;
        float: right;
        width: 15.7%;
        height: 146px;
    }
    .kqform-content {
        overflow: auto;
    }
    .query-condition{  
        min-height: 200px;
    }
    .layui-table th{
        overflow: hidden;
    }
    /* 人员节点 展开、折叠*/
    .ztree li span.button.diy01_ico_open, .ztree li span.button.diy01_ico_close{
        background-image: url('/start/plugin/zTree/css/zTreeStyle/img/icon-role.png');
    }
    /* 父节点展开 */
    .ztree li span.button.diy02_ico_open{
        background-image: url('/start/plugin/zTree/css/zTreeStyle/img/zTreeStandard.png');
        background-position: -110px -16px;
    }
    /* 父节点折叠 */
    .ztree li span.button.diy02_ico_close{
        background-image: url('/start/plugin/zTree/css/zTreeStyle/img/zTreeStandard.png');
        background-position: -110px 0;
    }

    /* 子节点 */
    .ztree li span.button.diy02_ico_docu{
        background-image: url('/start/plugin/zTree/css/zTreeStyle/img/zTreeStandard.png');
        background-position: -110px 0;
    }
    .ztree li span.button.diy01_ico_docu{
        background-image: url('/start/plugin/zTree/css/zTreeStyle/img/icon-role.png');
    }
    .ztree .no-data-tips{
        margin-top: 100px;
    }
    .layui-tab-content .layui-table th{
        border: 1px solid #e6e6ee;
    }
    /* .btn-look {
        width: 60px;
        border: 1px solid #0078FF;
        color: #0078FF;
    } */

    .btn-look{
        background-color: transparent;
        border: 1px solid #FF4E32;
        border-radius: 2px;
        position: relative;
        width: 24px;
        height: 22px;
        border: none;
        background-position: center center;
        background-repeat: no-repeat; 
        cursor: pointer;
    }
    .btn-look .layui-icon{
        position: absolute;
        top: -1px;
        left: 2px;
        font-size: 26px;
        color: #FF4E32 !important;
		border-color: #FF4E32;
    }
   .form-tab-content .layui-table-box   tbody tr.lineactive{
        background-color: #FDE7A3;
    }
    .queryListBox li{
        cursor: pointer;
    }
    .queryListBox li.liActive{ 
        background-color: #FFE6B0;
    }
</style>
<!-- 操作 -->
<script type="text/html" id="test-table-thead-barDemo">  
         <a class="layui-icon layui-icon-edit my-table-btn my-table-btn-edit" lay-event="edit" lay-tips="修改"></a> 
       
       <button class="  btn-look" lay-event="look" lay-tips="查看记录"><i class="layui-icon layui-icon-form"></i></button>
        <!-- <a class="layui-btn layui-btn-primary layui-btn-xs btn-look" lay-event="look">
                <span>查看记录</span> 
        </a> -->
</script>
<script>
    //验证表达式
    var valifyObj={
        'int':{
            reg: /^([^0][0-9]+|0)$/,
            text:"整数"
        },
        'decimal':{
            reg: /^(([^0][0-9]+|0)\.([0-9]{1,10})$)|^(([^0][0-9]+|0)$)|^(([1-9]+)\.([0-9]{1,10})$)|^(([1-9]+)$)/,
            text:"整数或者小数"
        }
    
    } 
    var saveErrorTip={};
    layui.use(['admin', 'table', 'element', 'tools', 'laytpl', 'form', 'laydate'], function(){
        var table = layui.table,
            element = layui.element,
            admin = layui.admin,
            view = layui.view,
            setter = layui.setter,
            tools = layui.tools,
            laytpl = layui.laytpl,
            form = layui.form,
            laydate = layui.laydate,
            router = layui.router();

        var colName = [], //列名
            tablename = [], //表单名
            condition= [], //查询条件
            supContent = [],
            delRows = [],
            layout = ['.layui-table th', '.layui-table td', '#data-dataSearch-kqform', '.ztree','#disFormBox .layui-form-label','#disFormBox .layui-input-inline'];
            window.tabIndex = 0; //选项卡下标 默认为0
            window.tableId = 'test-table-cellEdit1'; //选项卡表单id
            window.Id = '';
            window.writeid ='';
            window.taskId = '';
            window.link = '';
            window.taskname = '';
            window.checking = ''; 
        var  editClickFlag=false;//修改的标志
        var  clickTrObjId="";//点击的id 
        var saveClickFlag=false;//保存按钮点击
        var setting = {
            data: {
                key: {
                    name: 'taskname'
                },
                simpleData: {
                    enable: true,
                    idKey: "writeid",
                    pIdKey: "pId",
                    rootPId: 0
                }
            },
            async: {
                enable: true,
                type: 'get',
                url: 'myapi/DC/api/rest/web/custom/GetDisasterTask?access_token='+layui.data('layuiAdmin').access_token,
                dataFilter: ajaxDataFilter,
                autoParam: ['writeid']
            }, 
            callback: {
                onClick: zTreeOnClick
            }
        };
        tools.initCite(router, {kqfirstMenu: '考勤管理', kqsecondMenu: '考勤查询'}, {czfirstMenu: '数据应用', czsecondMenu: '数据查询'}); 
        
        tools.showTextTips('.form-tab-content');  
          //处理回调数据
          function ajaxDataFilter(treeId, parentNode, responseData){ 
            var nodesData = [];   
            if (responseData.data.retcode === '0' && responseData.data.data && responseData.data.data.length >0) {
                $.each(responseData.data.data, function (index, item) {
                    var writetype = item.writetype;
                    if(writetype == '2'){
                        item.iconSkin = 'diy02';
                        item.isParent = true;
                    }else if(writetype == '3'){
                        item.iconSkin = 'diy01';
                    }
                    nodesData.push(item);
                })
            } 
            return nodesData;
        }
        
        //渲染任务树
        function getTaskTree(){
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetDisasterTask',
                type: 'post',
                done: function(res){ 
                    if(res.retcode == '0' && res.data.data&& res.data.data.length > 0){
                        var zNodes = [];
                        layui.each(res.data.data, function(index, item){ //异步加载需要给第一级节点帮点isParent:true
                            var writetype = item.writetype;
                            if(writetype == '2'){
                                item.iconSkin = 'diy02';
                                item.isParent = true;
                            }else if(writetype == '3'){
                                item.iconSkin = 'diy01';
                            }
                            item.rootNode = '1';
                            zNodes.push(item);
                        }) 
                        var zTree =  $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                        var nodes = zTree.getNodes();
                        if(nodes.length > 0){
                            zTree.selectNode(nodes[0]); //默认选中指定节点
                            if(nodes[0].checking === '1') {
                                getKqTaskForm(nodes[0].id, nodes[0].taskid, nodes[0].link);
                                pickTypeShow('kqform');
                            }else {

                               // getTaskForm(nodes[0].id, nodes[0].taskid, nodes[0].link); //默认展示第一个节点表单
                                leftListQuery(nodes[0].taskid,nodes[0].dept_id);
                                pickTypeShow('other');
                            }
                            window.Id = nodes[0].id;
                            window.writeid = nodes[0].writeid;
                            window.dept_id = nodes[0].dept_id;
                            window.taskId = nodes[0].taskid;
                            window.link = nodes[0].link; 
                            window.taskname = nodes[0].taskname;
                            window.checking = nodes[0].checking;
                        }
                    }else {
                        var noDataHtml = '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>';
                        $('#treeDemo').empty().html(noDataHtml);
                        $('.form-tab-content').empty().html(noDataHtml);
                        $('.form-box').attr('style', 'height: 842px');
                    }
                }
            })
        }
        //任务树点击回调
        function zTreeOnClick(event, treeId, treeNode) {
            supContent = [];
            var flag = treeNode.rootNode && treeNode.rootNode == '1';
            flag ?  $('.layui-btn-urge').addClass('layui-btn-disabled') : $('.layui-btn-urge').removeClass('layui-btn-disabled');
            if(treeNode.checking === '1') {
                getKqTaskForm(treeNode.id, treeNode.taskid, treeNode.link);
                pickTypeShow('kqform');
            }else {
                // getTaskForm(treeNode.id, treeNode.taskid, treeNode.link);
                leftListQuery(treeNode.taskid,treeNode.dept_id);
                pickTypeShow('other');
            }
            window.taskId = treeNode.taskid;
            window.Id = treeNode.id;
            window.writeid = treeNode.writeid;
            window.dept_id = treeNode.dept_id;
            window.link = treeNode.link;
            window.checking = treeNode.checking;
            window.tabIndex = 0; //切换为默认状态
            window.tableId = 'test-table-cellEdit1';  
            window.taskname = treeNode.taskname;
        }

        //不同任务类型做不同的元素切换
        function pickTypeShow(type) {
            if(type === 'other') {
                $('.otherForm-content').show();
                $('.kqform-content').hide();
                $('.kq-time').hide();
            }else if(type === 'kqform') {
                $('.otherForm-content').hide();
                $('.kqform-content').show();
                $('.kq-time').show();
            }
        }
        //初始化左侧树
        getTaskTree();
        //初始化左侧列表 
        // initLeftList();
        function initLeftList(){ 
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetDisasterTask',
                type: 'post',
                data: {
                    access_token: layui.data('layuiAdmin').access_token 
                },
                success: function(res) {
                    if(res .data.retcode==0){ 
                        var listData=res.data.data;
                        if(listData&&listData.length>0){
                            var lis="";
                            for(var i=0;i<listData.length;i++){
                                lis+="<li taskid="+listData[i].taskid+">"+listData[i].taskname+"</li>"
                            }  
                            window.taskId="";
                            $("#queryListBox").empty().append(lis);
                            $("#queryListBox li").eq(0).click();
                        }
                    }
                    
                }
            })
                
        }
        //左侧列表点击事件
        // $("#queryListBox").delegate("li","click",function(){ 
        //         var taskid=$(this).attr("taskid");
        //         $(this).addClass("liActive").siblings().removeClass("liActive"); 
        //         window.taskId=taskid;
        //         leftListQuery(taskid);
        //     })
        //请求数据
        function leftListQuery(taskid,dept_id,depName){
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetDisasterDataByTaskid',
                type: 'post',
                data: {
                    taskid:taskid,
                    dept_id:dept_id,
                    dept_name:depName,
                    access_token: layui.data('layuiAdmin').access_token 
                },
                success: function(res) { 
                        if(res.data.retcode==0){
                            editClickFlag=false;//修改的标志
                            clickTrObjId="";//点击的id  
                            window.FormData = res.data.datas;
                            initFormItem(res.data.conditions);
                            initTableFun(res.data);
                        }
                }
            }) 
        }
           
            //初始化右侧form表单
        function initFormItem(field){  
            var getTpl = queryExihibt.innerHTML,
                $view = document.getElementById('layui-query-box');
                laytpl(getTpl).render(field, function(html){
                    $view.innerHTML = html;
                });  
            $(".depNameBox").text("")
            $(".query-condition").css({"height":Math.ceil(field.length/3)*54+"px"}); 
        } 
        //初始化表格数据
        function initTableFun(result){
            var colsss=[]; 
            var fields=result.fields;
            colsss.push({ type: 'numbers', title: '序号', width: 44 })
            colsss.push({ field:'dept_name', title: '单位', width: 160,templet: function(d){
                        return '<span lay-tips="'+ d.dept_name +'">'+ d.dept_name +'</span>' 
                    }})
            for(var i=0;i<fields.length;i++){
                var eachField=fields[i]; 
                var width=""; 
                if(eachField.column_name=="memo"){
                    width=160 
                }else{
                    width=eachField.column_comment.length*20
                } 
                (function(i){
                    colsss.push({
                    field:eachField.column_name,
                    title:eachField.column_comment,  
                    hide:eachField.fill=="0"?true:false, 
                    width:width,  
                    templet: function(d){  
                        return '<span lay-tips="'+ d[fields[i].column_name] +'">'+ d[fields[i].column_name] +'</span>' 
                    }
                })
                })(i);
                
            }
            colsss.push({ field:'user_name', title: '操作人', width: 160,templet: function(d){
                        return '<span lay-tips="'+ d.user_name +'">'+ d.user_name +'</span>' 
                    }})
            colsss.push({ field:'createtime', title: '操作时间', width: 200,templet: function(d){
                return '<span lay-tips="'+ d.createtime +'">'+ d.createtime +'</span>' 
            }})
            colsss.push( { field: 'opearte', title:'操作', toolbar: '#test-table-thead-barDemo', width: 120 })  
             
            table.render({
                elem: '#test-table-cellEdit'
                ,cols: [colsss]
                ,text: {
                    none: '<div class="no-data-tips"><img src="/src/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                }
                ,skin: 'nob'
                ,height: 460
                ,even: true
                ,limit: 5000 
                ,data:result.datas
                ,done: function(res, curr, index){
                    tools.setFont(layout);
                }
            });
        }  
        //设置表单值
        function setFormData(clickTrParam,id){ 
                for(var key in clickTrParam){
                    var _this=$('#'+id).find("[name='"+key+"']");
                    var tagName=$('#'+id).find("[name='"+key+"']").prop("tagName");//标签名
                    $(".depNameBox").text("单位："+clickTrParam.dept_name)
                    switch(tagName){
                        case "INPUT": 
                            $(_this).val(clickTrParam[key]); 
                            break;
                        case "SELECT": 
                            $(_this).val(clickTrParam[key]);  
                            break;
                        case "TEXTAREA":
                            $(_this).val(clickTrParam[key]); 
                            break;	
                    }
                }
            }
             //判断表单项是否为空
        function isEmpty(strParam){
            for(var key in strParam){
                var obj=strParam[key];  
                if(typeof obj == "undefined" || obj == null || obj == ""){
                    return true;
                } 
            }
            return false;   
        }
         
         //获取表单所有数据 
         function getFormParam(id){
            var formArr=$('#'+id).serializeArray();
            var addParam={};
            for(var i=0;i<formArr.length;i++){
                var nameO=formArr[i].name; 
                addParam[formArr[i].name]=formArr[i].value; 
            }
            return addParam;
        }
        // //表格点击
        // table.on('row(test-table-cellEdit)', function(obj){ 
        //         setFormData(obj.data,"layui-query-box")
        // })
        //催办点击操作
        $(".layui-btn-urge").click(function(){
            var isDisalbed = $(this).hasClass('layui-btn-disabled');
                if(isDisalbed){
                    return ;
                }
                layer.open({
                    id: 'urgememo',
                    type: 1,
                    title: '<i class="formFill-icon"></i><span style="color:#FFF;">催办消息</span>',
                    area: ['300px', '250px'],
                    offset: 'auto',
                    shadeClose: true,
                    resize: false,
                    success: function(lay, index){
                        view(this.id).render('./audit/components/usermemo', {
                            showReview: false
                        });
                    },
                    btn: ['确定', '取消'],
                    btnAlign: 'c',
                    yes: function(index, layero){
                        var memoval = $('#urgememo .layui-textarea').val();
                        if($.trim(memoval) == ''){
                            layer.msg('请填写催办消息', {time: 1000});
                            return ;
                        }
                        admin.req({
                            url: 'myapi/DC/api/rest/web/custom/Pressdo',
                            type: 'post',
                            data: {
                                model: 'add',
                                taskid: window.taskId,
                                writeid: window.writeid, 
                                memo: memoval 
                            },
                            done: function(res){
                                if(res.retcode == '0'){
                                    layer.msg('催办成功', {time: 1000});
                                    layer.close(index);
                                }
                            }
                        })
                    }
                })
        })
        //导出数据
        $(".btn-subform").click(function(){  
            var formdata = window.FormData;
                if(window.checking === "1") {
                    var aWriteName = $('.left-card-body').find('input[name="writeusername"]').val(),
                        url = 'myapi/DC/api/rest/web/custom/checkworkExportExcel'; 
                }else {
                    if(formdata && formdata.length > 0){
                        var sheet = [];
                        // layui.each(formdata, function(index, item){
                        //     var obj = {};
                        //     obj.formname ="表格数据";
                        //     var headerArr=tools.getSerachData('test-table-cellEdit', 'thead');
                        //     headerArr.pop();    
                        //     obj.header = JSON.stringify(headerArr);
                        //     obj.data = JSON.stringify(tools.getSerachData('test-table-cellEdit', 'searchBodyData2'));
                        //     sheet.push(obj);
                        // }); 
                        var obj = {};
                        obj.formname ="表格数据";
                        var headerArr=tools.getSerachData('test-table-cellEdit', 'thead');
                        // headerArr.pop();    
                        obj.header = JSON.stringify(headerArr);
                        obj.data = JSON.stringify(tools.getSerachData('test-table-cellEdit', 'searchBodyData2'));
                        sheet.push(obj);

                        var url = 'myapi/DC/api/rest/web/custom/taskExcelDataDownload';
                        tools.downLoadfunction(url,{
                            taskname: window.taskname,
                            sheets: JSON.stringify(sheet),
                            access_token: layui.data(setter.tableName)[setter.request.tokenName]
                        });
                    }else{
                        layer.msg('没有需要导出的数据', {time: 1000});
                    }
                }  
        })
        
        //保存点击 
        $(".layui-btn-save").click(function(){
            var FormParam=getFormParam("disFormBox"); 
            if(editClickFlag){//点击了修改 
                    if(!isEmpty(FormParam)){  

                        if(!saveClickFlag&&isEmptyObj(saveErrorTip)){ 
                                saveClickFlag=true;
                                saveErrorTip={};
                                FormParam.id=clickTrObjId;
                                var saveFormParam={ 
                                    data:JSON.stringify(FormParam),
                                    access_token: layui.data('layuiAdmin').access_token
                                }
                                admin.req({
                                    url: 'myapi/DC/api/rest/web/custom/FillDataSave',
                                    data:saveFormParam,
                                    type:"post",
                                    done: function(res){ 
                                        if(res.data.retcode==0){   
                                            layer.msg(res.data.retmsg,{time:1000},function(){ 
                                                saveClickFlag=false; 
                                                leftListQuery(window.taskId,window.dept_id);  
                                            })
                                        }else{ 
                                            saveClickFlag=false;
                                            layer.msg(res.data.retmsg,{time:1000})
                                        }
                                    },
                                    error:function(erro){
                                        console.log(erro);
                                    }
                                })
                            }else{
                                var keyIndex=0;
                                for(var key in saveErrorTip){
                                    if(saveErrorTip[key]&&keyIndex==0){
                                        layer.msg(key+"字段类型为"+saveErrorTip[key]+"，请重新输入！",{time:1000})
                                        keyIndex++;
                                    } 
                                } 
                            }
                    }else{
                        layer.msg("输入内容不能为空！",{time:1000})
                    } 
            }else{
                layer.msg("请选择需要修改的数据!",{time:1000})
            }
        })
        function isEmptyObj(obj){
            for(var key in obj){
                return false
            }
            return true
        }
        //查看记录点击
        table.on('tool', function(obj){  
                var event=obj.event;
                    if(event=="look"){
                        admin.req({
                        url: 'myapi/DC/api/rest/web/custom/GainHistory',
                        data: {
                            id: obj.data.id
                        },
                        done: function(res){
                            if(res.retcode == '0'){
                                if(res.data && res.data.length > 0){
                                    var taskrecode = layer.open({
                                        id: 'temporary-addhtml',
                                        title:'<i class="formFill-icon"></i><span style="color:#FFF;">查看填报记录</span>',
                                        offset: '110px',
                                        type: 1,
                                        resize: false,
                                        shadeClose: true,
                                        area: ['800px', '450px'],
                                        success: function(lay, index){
                                            view(this.id).render('./disasterPage/components/disHistory', {history: res.data});
                                        }
                                    });
                                }else{
                                    layer.msg('暂无记录', {time: 1500});
                                }
                            }
                        }
                    })
                }else if(event=="edit"){ 
                    clickTrObjId=obj.data.id;
                    $('[lay-id="test-table-cellEdit"]').find(obj.tr.selector).addClass('lineactive');
                    $('[lay-id="test-table-cellEdit"]').find(obj.tr.selector).siblings().removeClass('lineactive'); 
                    setFormData(obj.data,"layui-query-box");
                    editClickFlag=true;
                }
        })
         
        //查询事件
        $('.form-box').delegate('#query', 'click', function() {
            leftListQuery(window.taskId,window.dept_id,$("#dept_name").val());
        }); 
        //给enter绑定查询
        $('body').keydown(function(){
            if(event.keyCode == '13'){
                $('#query').click();
            }
        });
            //右边
        $("#disFormBox").delegate(".valifyInput", "blur", function(){ 
            var _thisValue=Number($(this).val()),_thisInputType=$(this).attr("inputType");
            var labelTxt=$(this).parents('.layui-input-inline').siblings('label').html();
            if(_thisInputType=="int"||_thisInputType=="decimal"){
                if(!valifyObj[_thisInputType].reg.test(_thisValue)){
                    layer.msg('该列字段类型为'+valifyObj[_thisInputType].text+'格式，请正确输入！', {time: 1500});  
                    saveErrorTip[labelTxt]=valifyObj[_thisInputType].text;
                    saveClickFlag=true; 
                }else{ 
                    delete saveErrorTip[labelTxt];
                    saveClickFlag=false;
                }
            } 
        });
    })
</script>